package app;

import command.*;
import pojo.*;
import util.*;

public class OrderApp {
	private OrderApp() {	
	}
	
	private static OrderApp instance = null;
	
	public static synchronized OrderApp getInstance(){
		if(instance == null){
			instance = new OrderApp();
		}
		return instance;
	}
	
	private User user = null;
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public static void setInstance(OrderApp instance) {
		OrderApp.instance = instance;
	}
	
	public static void main(String[] args) {
		OrderConsole.println("-------欢迎来到订单管理系统------\n");
		OrderConsole.println(">>输入help查看帮助文档                  ");
		
		while (true) {
			String cmd = OrderConsole.askUserInput("cmd");
			CommandCode commandCode=null;
			try {
				commandCode = CommandCode.valueOf(cmd.toUpperCase());
			} catch (Exception e) {
				OrderConsole.println("非法命令");
				continue;
			}
			CommandFactory factory = CommandFactory.getFactory(getInstance().getUser());
			Command command = factory.buildCommand(commandCode);
			if(command==null){
				continue;
			}
			command.execute();
		}
	}
}
